<script type="text/javascript">
<!--
$(function(){
	$(".button").button();
});

// Mouseover Tabs
//$(".idTabs").idTabs("mouseover");

// Url Saving Tabs
//$(".idTabs").idTabs(true,location.hash);

function getIds(){

	var ids = new Array();
	$(".view").each(function(){
		ids.push($(this).attr("id"));
	});
	return ids;


}


function load(){
	
	var ids = getIds();
	var id;
	var store = '';

	
	for(i in ids){
		
		id = ids[i];		
		
		$.get('<?php echo  $this->createUrl('comment/reply');?>',{id:id},function(data){
			if (data != 'false'){
				result = data.split('#-#');

				if($("#"+result[0]).find(".arc-content").length == 1){
					setDefault();
					
					$("#"+result[0]).find(".arc-content").append(result[1]).fadeIn(5000);					
				}
			}
		});
		
	}
	
}

window.setInterval('load()',5000);

function setDefault(){

	setDefaultContent($(".reply-input"),'回复此评论');
	setDefaultContent($(".reply-author"),'网名');
	setDefaultContent($(".reply-email"),'邮箱');
	setDefaultContent($(".reply-texteara"),'……');
	
}

function setDefaultContent(object,val){


	object.each(function(i){
		if($(this).val() == ''){
			$(this).val(val);

		}
//		if($(this).val() == val){
//			$(this).next().val('');
//		}
	});

}
function changeInputToTexteara(object){
//	object.parent().append('<textarea class="reply-input" style="width:90%;height:50px;" onblur="changeTextAeraToInput($(tihs))" />');
	object.hide().next().show();
}

function changeTextAeraToInput(object){

	var author = object.prev().prev().prev().val();
	var email = object.prev().prev().val();
	var content = object.val();

	
	var str = author + '-' + email + '-' + content;

	
	object.parent().hide().siblings('.reply-input').val(str).show();

	
//	object.next().hide();

	var id = object.attr("id");
	var ids = id.split("-");
	ids.pop();

	var rid = ids[0].split(':')[1];
	var aid = ids[1].split(':')[1];

	
	if(object.val() != '' && object.val() != '……'){

	    $.msgbox({
	        height:100,
	        width:250,
	        content:{type:'confirm', content: '确认提交评论内容！'},
	        animation:4,
	        onClose:function(v){
				if(v){
					$.post('<?php echo $this->createUrl('comment/create'); ?>',{
							'Comment[com_rid]':rid,
							'Comment[com_aid]':aid,
							'Comment[com_author]':author,
							'Comment[com_email]':email,
							'Comment[com_contents]':content,
						},function(data){

							if(data == 'ok'){
							       $.msgbox({
							            height:100,
							            width:250,
							            content:{type:'alert', content: '评论成功，请等候审核！'},
							            animation:4
							       });
				
							}
					});
				}
	        }
	   });
		

	}
}

function actionCreateComment(){

	var json = {
		'Comment[com_aid]':$("#Comment_com_aid").val(),
		'Comment[com_status]':$("#Comment_com_status").val(),
		'Comment[com_author]':$("#Comment_com_author").val(),
		'Comment[com_email]':$("#Comment_com_email").val(),
		'Comment[com_website]':$("#Comment_com_website").val(),
		'Comment[com_contents]':$("#Comment_com_contents").val(),
	};

	$.post('<?php echo $this->createUrl('comment/create');?>',json,function(data){
		if(data == 'ok'){
		       $.msgbox({
		            height:100,
		            width:250,
		            content:{type:'alert', content: '评论成功，请等候审核！'},
		            animation:4
		       });

		}
	});

	
}
//-->
</script>
<?php
$pid = explode(',', $model->arc_cid);
$pid = $pid[0];
$menu = array_reverse(Category::model()->generateBreadcrumbs($pid));

$this->breadcrumbs = array_merge($this->breadcrumbs,$menu);
$this->breadcrumbs = array_merge($this->breadcrumbs,array(UtilTools::strSlice($model->arc_title,0,50)));

$this->pageTitle = Category::model()->generatePageTitle(array_reverse($this->breadcrumbs,'_')).Yii::app()->name;

//	 $this->widget('ext.editor.syntaxhighlighter.syntaxhighlighterWidget',array(
//		'theme'=>'Django'
//));
?>



	<?php $this->widget('application.components.blog.blogPreNext',array(
		'id'=>$model->arc_id
	))?>
	<hr class="space" />
	<div class="arc-title" style="text-align:center;">
		<h3><?php echo $model->arc_title; ?></h3>
		<?php echo Yii::t('common','<span>Post By {user} On {time} Hits {hits};?></span>',array(
				'{user}'=>$model->author->user_name,
				'{time}' => UtilTools::timeop($model->arc_created),
				'{hits}' => $model->arc_hits
		))?>		
	</div>	
	<div class="arc-content">
	
	<?php $this->widget('ext.code.syntaxhighlighter.syntaxhighlighterWidget');?>


		<?php echo $model->arc_content;?>
	</div>
	
	<hr class="space" />
	<?php $this->widget('application.components.blog.blogPreNext',array(
		'id'=>$model->arc_id
	))?>
	<hr class="space" />
	
	<?php $this->widget('application.components.visitors.visitorsWidget',array(
		'queryID' => $model->arc_id
	));?>
	
	
	<?php /*	
	<?php if (!Yii::app()->user->isGuest):?>
	最近访客：<br />
		<?php foreach ($visitors as $vdata):?>
		<?php //UtilTools::dump($vdata->attributes);?>
		<?php echo Visitors::model()->getVisitorHead(long2ip($vdata->visitors_ip),array('style'=>'width:50px;'), '最后访问时间:'.date('Y-m-d h:i:s', $vdata->visitors_lasttime));?>
		<?php endforeach;?>
	<?php endif;?>
	*/
	?>

	<?php  $this->widget('ext.idTabs.idTabsWidget'); ?>
 
     <div class="idTabs">

		<div class="tabsHeader">
			<ul>
				<li><a href="#one">相关评论</a></li>
				<li><a href="#two">评上一言</a></li>
			</ul>
      </div>
      <hr class="space" />
     	<div class="idTabs-items" style="width:100%;">
	        <div id="one">
				<div class="box" style="margin:0px;width:100%;padding:5px;">
					<div class="box-title">相关评论</div>
					<div class="box-content">
						<?php $this->widget('zii.widgets.CListView', array(
							'dataProvider'=>$commentData,
							'itemView'=>'/comment/_view',
						)); ?>
					</div>
				</div>        
	        </div>	       
	        <div id="two">
	        	<div class="box"  style="margin:0px;width:100%;padding:5px;">
	        		<div class="box-title">评上一言</div>
					<div class="box-content" style="height:300px;">
	        			<?php echo $this->renderPartial('/comment/_form', array('model'=>$comment)); ?>
	        		</div>
	        	</div>
	        </div>
      </div>
      <hr class="space" />
    </div>
 <?php $this->widget('ext.msgbox.msgboxWidget');?>